//
//  Dictionary+ExtensionTests.swift
//  TDDStudySwift
//
//  Created by baidu on 7/1/16.
//  Copyright © 2016 caoyuan. All rights reserved.
//

import XCTest

class Dictionary_ExtensionTests: XCTestCase {

    override func setUp() {
        super.setUp()
        // Put setup code here. This method is called before the invocation of each test method in the class.

    }
    
    override func tearDown() {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
        super.tearDown()
    }
    
    
    func testHasKeys() -> Void {
        let dict = ["key1":"value1","key2":123,"key3":[1,2,"3"]]
        let res = dict.pyHaskey(key:"key1")
        XCTAssertEqual(res, true)
    }
    
    func testHasKeys2() -> Void {
        let dict = ["key1":"value1","key2":123,"key3":[1,2,"3"]]
        let res = dict.pyHaskey(key:"key12323")
        XCTAssertEqual(res, false)
    }
 
    func testHasValue() -> Void {
        let dict = ["key1":"value1","key2":123,"key3":[1,2,"3"]]
        let res = dict.pyHasValue(object: 123)
        XCTAssertEqual(res, "key2")
    }
    
    func testHasValue2() -> Void {
        let dict = ["key1":"value1","key2":123,"key3":[1,2,"3"]]
        let res = dict.pyHasValue(object: 2131)
        XCTAssertEqual(res, nil)
    }
    
    func testForEach() -> Void {
        var dict = ["key1":"value1","key2":123,"key3":[1,2,"3"]]
        dict.forEach { (key, value) in
            print("😄👉\(key):\(value)👈😄")
            if key == "key2"{dict[key] = "fffff"}
        }
        print("😄👉\(dict)👈😄")
        XCTAssertEqual(dict, ["key1":"value1","key2":"fffff","key3":[1,2,"3"]])
    }
  

}
